<?php namespace App\Http\Controllers\user\uc;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Session;
use Input;
use App\Models\News;

class InformationController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}

	public function addNews()
	{
		$uid = $this->getUid();
		if($uid){
			$model = new News;
			$data = Input::all();
			$data['uid'] = $uid;
			$model->create($data);
			return $this->json([]);
		}
	}

	public function editNews()
	{
		$nid = (int)Input::get('nid', 0);
		$uid = $this->getUid();
		$model = News::where("id", $nid);
		if($model->count()){
			if($model->get()[0]->uid == $uid){
				$data = Input::except('nid');
				if($model->update($data)){
					return $this->json([]);
				}
			}
		}
	}

	public function newsList()
	{
		$nid = Input::get('nid',0);
		$uid = $this->getUid();
		$model = News::where('id', $nid);
		if($model->count()){
			if($model->get()[0]->uid == $uid){
				$data = $model->get()[0];
				return $this->json($data);
			}else{
				self::error(slef::NO_DATA);
			}
		}else{
			self::error(slef::NO_DATA);
		}
	}

	public function deleteNews()
	{
		$nid = (int)Input::get('nid', 0);
		$uid = $this->getUid();
		$model = News::where('id', $nid);
		if($model->get()){
			if($model->get()[0]->uid == $uid){
				if($model->delete()){
					return $this->json([]);
				}

			}
		}
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
